//
//  ShopCommentTableViewCell.m
//  FaceCard
//
//  Created by 瞿伦平 on 2017/5/8.
//  Copyright © 2017年 瞿伦平. All rights reserved.
//

#import "ShopCommentTableViewCell.h"

@implementation ShopCommentTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code.
        self.selectionStyle=UITableViewCellSelectionStyleNone;
        [self.contentView setAutoresizingMask:UIViewAutoresizingFlexibleHeight];
        
        float padding = 5;
        UIFont *font = [UIFont systemFontOfSize:14];
        UIColor *color = [UIColor grayColor];
        UIView *superView = self.contentView;
        
        UIView *aView = ({
            UIView *view = [superView newUIView];
        
            self.logoImgView = [view newUIImageViewWithImg:IMG(@"defultHeadEdit.png")];
            self.logoImgView.layer.cornerRadius = 15;
            self.logoImgView.layer.masksToBounds = YES;
            
            self.nameLable = [view newUILableWithText:@"匿名用户" textColor:[UIColor blackColor] font:font];
            self.timeLable = [view newUILableWithText:@"2017-05-11" textColor:color font:[UIFont systemFontOfSize:13] textAlignment:NSTextAlignmentRight];
            
            HCSStarRatingView *starRatingView = [[HCSStarRatingView alloc] init];
            starRatingView.maximumValue = 5;
            starRatingView.minimumValue = 0;
            starRatingView.value = 0;
            starRatingView.spacing = 1;
            starRatingView.tag = 21;
            starRatingView.tintColor = STAR_COLOR;
            starRatingView.allowsHalfStars = YES;
            starRatingView.userInteractionEnabled = NO;
            [view addSubview:starRatingView];
            self.starView = starRatingView;
            
            [self.logoImgView makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(view.left).offset(padding);
                make.width.height.equalTo(kShopCommentTableViewCell_HeaderImgHeight);
                make.centerY.equalTo(view.centerY);
            }];
            [self.nameLable makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(_logoImgView.right).offset(padding);
                make.top.equalTo(view.top).offset(padding/2);
                make.bottom.equalTo(view.centerY);
            }];
            [self.timeLable makeConstraints:^(MASConstraintMaker *make) {
                make.left.greaterThanOrEqualTo(_nameLable.right).offset(padding/2);
                make.top.bottom.equalTo(_nameLable);
                make.right.equalTo(view.right).offset(-padding);
            }];
            [self.starView makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(_nameLable.left);
                //make.top.equalTo(view.centerY).offset(padding/2);
                //make.bottom.equalTo(view.bottom).offset(-padding/2);
                make.top.equalTo(view.centerY);
                make.height.equalTo(20);
                make.width.equalTo(70);
            }];
            view;
        });
        [aView makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(superView);
            make.top.equalTo(superView.top).offset(padding);
            make.height.equalTo(45);
        }];

        
        self.commentLable = [superView newUILableWithText:@"不错" textColor:color font:font];
        self.commentLable.numberOfLines = 0;
        //self.commentLable.backgroundColor = [UIColor redColor];
        
        [self.commentLable makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(superView.left).offset(kShopCommentTableViewCell_HeaderImgHeight + padding);
            make.right.equalTo(superView.right).offset(-padding);
            make.top.equalTo(aView.bottom);
            //make.bottom.equalTo(superView.bottom).offset(-padding/2);
        }];
        
        
//        self.photosView = [[ImgShowView alloc] init];
//        [superView addSubview:_photosView];
//        [self.photosView makeConstraints:^(MASConstraintMaker *make) {
//            make.left.right.equalTo(_commentLable);
//            make.top.equalTo(_commentLable.bottom).offset(padding/2);
//            make.height.equalTo(kShopCommentTableViewCell_CommentImgHeight);
//        }];
        
//        // 2.1 创建一个流水布局photosView(默认为流水布局)
//        PYPhotosView *flowPhotosView = [PYPhotosView photosView];
//        //flowPhotosView.pageType = PYPhotosViewPageTypeLabel;
//        flowPhotosView.layoutType = PYPhotosViewLayoutTypeLine;
//        flowPhotosView.autoLayoutWithWeChatSytle = NO;
//        flowPhotosView.autoRotateImage = NO;
//        flowPhotosView.placeholderImage = IMG(@"bj.png");
//        flowPhotosView.backgroundColor = [UIColor redColor];
//        flowPhotosView.py_x = kShopCommentTableViewCell_HeaderImgHeight;
//        flowPhotosView.py_width = self.py_width - [ShopCommentTableViewCell commentLableWidth];
//        
//        self.flowPhotosView = flowPhotosView;
//        [superView addSubview:flowPhotosView];
//        [flowPhotosView makeConstraints:^(MASConstraintMaker *make) {
//            //make.left.right.equalTo(_commentLable);
//            make.top.equalTo(_commentLable.bottom).offset(padding/2);
//            //make.top.equalTo(50);
//            make.height.equalTo(kShopCommentTableViewCell_CommentImgHeight);
//        }];
        
    }
    return self;
}

+(CGFloat)commentLableWidth
{
    return DEVICE_Width - kShopCommentTableViewCell_HeaderImgHeight - (10*2);
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}



@end
